﻿using System.Xml;

namespace ExportWordBibModule.SchemaImplementation
{
    /// <summary>
    /// Author
    /// </summary>
    public class Author
    {
        const string ns = Constants.BibliographyNamespace;
        const string b = Constants.BibliographyPrefix;

        /// <summary>
        /// Gets or sets the first name.
        /// </summary>
        /// <value>The first.</value>
        public string First { get; set; }
        /// <summary>
        /// Gets or sets the last name.
        /// </summary>
        /// <value>The last.</value>
        public string Last { get; set; }
        /// <summary>
        /// Gets or sets the middle name.
        /// </summary>
        /// <value>The middle.</value>
        public string Middle { get; set; }

        /// <summary>
        /// Renders the author as XML node.
        /// </summary>
        /// <returns></returns>
        public XmlNode Render()
        {
            // Author
            XmlDocument document = new XmlDocument();
            var authorNode = document.CreateElement(b, "Author", ns);
            document.AppendChild(authorNode);

            // Author
            var bookAuthorNode = document.CreateElement(b, "Author", ns);
            authorNode.AppendChild(bookAuthorNode);

            // Name list
            var nameListNode = document.CreateElement(b, "NameList", ns);
            bookAuthorNode.AppendChild(nameListNode);

            // Person
            var personNode = document.CreateElement(b, "Person", ns);
            nameListNode.AppendChild(personNode);

            // Last name
            var lastNode = document.CreateElement(b, "Last", ns);
            lastNode.InnerText = Last;
            personNode.AppendChild(lastNode);

            // First name
            var firstNode = document.CreateElement(b, "First", ns);
            firstNode.InnerText = First;
            personNode.AppendChild(firstNode);

            // Middle name
            var middleNode = document.CreateElement(b, "Middle", ns);
            middleNode.InnerText = Middle;
            personNode.AppendChild(middleNode);

            return authorNode;
        }
    }
}
